feat(asyncpg): Add query source to execute, executemany, and cursor methods#6242
feat(asyncpg): Add query source to execute, executemany, and cursor methods#6242ericapisani wants to merge 14 commits into
Conversation
Migrates the asyncpg integration to use `record_sql_queries_supporting_streaming` and `StreamedSpan`, adding support for the `stream` trace lifecycle. Tests are parameterized to cover both static and streaming modes. Fixes PY-2305 Fixes #6003
…an has been created. This allows the traces_sampler to see the attributes and make decisions based on them
Add add_query_source() calls to execute(), executemany(), and cursor() methods. Previously only fetch() had query source tracking. Handle StreamedSpan and regular span cases separately since StreamedSpan requires the call while still inside the context manager. Add comprehensive test coverage for query source tracking across all wrapped methods.
Codecov Results 📊✅ 146 passed | Total: 146 | Pass Rate: 100% | Execution Time: 21.53s 📊 Comparison with Base Branch
✨ No test changes detected All tests are passing successfully. ❌ Patch coverage is 0.00%. Project has 14383 uncovered lines. Files with missing lines (1)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
+ Coverage 29.50% 34.90% +5.4%
==========================================
Files 190 190 —
Lines 22082 22094 +12
Branches 7426 7434 +8
==========================================
+ Hits 6514 7711 +1197
- Misses 15568 14383 -1185
- Partials 662 807 +145Generated by Codecov Action |
…to-methods-that-were-missing-it
sentrivana
left a comment
There was a problem hiding this comment.
One comment re: naming in tests https://github.com/getsentry/sentry-python/pull/6242/changes#r3225427754
Otherwise lgtm!
There was a problem hiding this comment.
Why do we add query source to _wrap_cursor_creation()?
My understanding is that the add_query_source() function is intended to add the query source to functions that execute SQL queries, which are only the following:
asyncpg.Connection.executeasyncpg.Connection._executeasyncpg.Connection._executemany
The parameter description says the following:
sentry-python/sentry_sdk/consts.py
Line 1559 in 17cc8c7
Can we ensure that only spans for these functions have query source added?
When this PR was initially created, I hadn't yet noticed the underlying issue with how we've patched cursors, and that this only captured the creation of the At this point, due to the introduction of #6252 , this PR is somewhat out of date in that cursor creation is no longer patched - the underlying This means that, with those changes:
and we'll want to add query sources to those. |
…ans since they're not fetching rows
Summary
add_query_source()calls to_wrap_connection_methodand_wrap_cursor_method, which coverexecute(),executemany(),prepare(),_bind_exec(), and_exec. Previously onlyfetch()had query source tracking via the patched_wrap_executemethod.StreamedSpanvs regular span cases separately (StreamedSpan needs the call inside the context manager).